package Fliter;

import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.Reader;

public class BookFliter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //判断读者是否有登录
        HttpSession session=((HttpServletRequest)servletRequest).getSession();
        Reader reader=(Reader) session.getAttribute("reader");
        if(reader ==null){
            ((HttpServletResponse)servletResponse).sendRedirect("login.jsp");
        }
        else {
            filterChain.doFilter(servletRequest,servletResponse);
        }
    }
}
